<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <script>
    //pending->fulfilled时，执行then的第一个回调函数
    //pending->rejected时，执行then的第二个回调函数
    //then方法执行后返回一个新的promise对象
    const p = new Promise((resolve, reject) => {
      // resolve()
      reject()
    })
    const p2 = p.then(() => {
      console.log('success');
    }, () => {
      console.log('err');
      //在then的回调函数中，return后面的东西，会用promise包装一下
      //默认返回的永远都是成功状态的promise对象
      // return undefined
      //等价于
      // return new Promise(resolve=>{
      //   resolve(undefined)
      // })
      return new Promise((resolve,reject)=>{
        reject('reason')
      })
    }).then(() => {
      console.log('success1');
    }, (err) => {
      console.log(err);
      return new Promise((res,rej)=>{
        rej('错误信息')
      })
    }).then(data=>{
      console.log(data);
    },err=>{
      console.log(err);
    })
    console.log(p, p2, p === p2);
  </script>
</body>

</html>